import { Router } from "jsr:@oak/oak/router";
import { authMiddleware } from "../middleware/authMiddleware.ts";
import { getAuth } from "../services/auth.ts";
import type { ApiResponse } from "../shared/types.ts";

const router = new Router();

router.post("/api/auth/logout", authMiddleware, async (ctx) => {
  try {
    const auth = getAuth();
    const token = ctx.request.headers.get("Authorization")!.substring(7);
    
    // 执行登出操作
    await auth.logout(token);
    
    const response: ApiResponse<null> = {
      success: true,
      data: null
    };
    
    ctx.response.body = response;
  } catch (error) {
    throw error;
  }
});

export default router; 